<template>
  <div class="div">
    <div class="div1">
      <que :queList="queList" :butFlag="!butFlag" @query="query" :querys="querys"/>
    </div>
    <div class="divs">
      <Tables :items="items" :butFlag="!butFlag" :borderFlag="butFlag" :list="list" :loading="loading" :high="high"/>
    </div>
    <el-col :md="{span: 5, offset: 6}" :lg="{span: 4, offset: 10}">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[20, 30, 40, 50]"
        :page-size="pagesize"
        :current-page="page"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-col>
  </div>
</template>
<script>
  import Tables from '../components/Tables.vue'
  import axios from 'axios'
  import Que from '../components/Que.vue'
  import moment from 'moment'
  import {mapState} from 'vuex'
  export default{
    name: 'Logg',
    components: {
      Que,
      Tables
    },
    data () {
      return {
        list: [],
        high: 0,
        loading: false,
        butFlag: true,
        items: [
          {
            prop: 'recordDate',
            label: '操作时间',
            meth: function (row, column) {
              var date = row[column.property]
              if (date === null) {
                return date
              } else {
                return moment(date).format('YYYY-MM-DD HH:mm:ss')
              }
            },
            table: true
          },
          {
            prop: 'recordor',
            label: '操作员',
            table: true
          },
          {
            prop: 'type',
            label: '操作内容',
            table: true
          }
        ],
        queList: [
          {
            width: '2',
            name: '操作员',
            prop: 'recordor',
            i1: '0'
          },
          {
            width: '3',
            name: '开始时间',
            prop: 'recordDate1',
            i2: '0'
          },
          {
            width: '3',
            name: '结束时间',
            prop: 'recordDate2',
            i2: '0'
          }],
        page: 1,
        pagesize: 20,
        total: 0,
        recordor: '',
        recordDate1: '',
        recordDate2: '',
        querys: {
          recordor: '',
          recordDate1: '',
          recordDate2: ''
        }
      }
    },
    computed: {
      ...mapState({
        isLogin: state => state.eui.isLogin,
        username: state => state.eui.username
      })
    },
    created () {
      if (!sessionStorage.getItem('username')) {
        this.$router.replace('/')
      }
    },
    mounted () {
      this.get()
      this.high = window.innerHeight - 230
    },
    methods: {
      handleCurrentChange (val) {
        this.page = val
        this.get()
      },
      handleSizeChange (val) {
        this.pagesize = val
        this.get()
      },
      query (msg) {
        if (msg.recordDate1 && msg.recordDate2 && msg.recordDate1 > msg.recordDate2) {
          this.$message.error('结束日期应大于开始日期')
        } else {
          if (msg.recordDate1 === null || msg.recordDate1 === undefined) {
            this.recordDate1 = msg.recordDate1
          } else {
            this.recordDate1 = new Date(msg.recordDate1).getTime()
          }
          if (msg.recordDate2 === undefined || msg.recordDate2 === null) {
            this.recordDate2 = msg.recordDate2
          } else {
            this.recordDate2 = new Date(msg.recordDate2).getTime()
          }
        }
        this.recordor = msg.recordor
        this.page = 1
        this.get()
      },
      get () {
        this.loading = true
        axios({
          method: 'get',
          url: `${this.BASE_URL}/logg/getAll`,
          responseType: 'json',
          params: {
            page: this.page,
            pagesize: this.pagesize,
            recordor: this.recordor,
            recordDate1: this.recordDate1,
            recordDate2: this.recordDate2
          }
        }).then((response) => {
          if (response.data.statuCode === '0') {
            this.loading = false
            this.total = response.data.total
            this.list = response.data.data
          } else {
            this.list = []
            this.loading = false
            this.$alert('没有相关内容', '提示', {
              confirmButtonText: '确定'
            })
          }
        }).catch(() => {
          this.loading = false
        })
      }
    }
  }
</script>
<style scoped>
  .div1 {
    width: 100%;
    height: 50px;
    padding-top: 10px;
  }

  .divs {
    margin-top: 30px;
  }
</style>
